

<template>
  <view class="Mall4j InvitationCards-mian">
    <view class="InvitationCards-ont">
      <view class="InvitationCards-in">
        <view class="title">
          <view class="hrLineLeft">
            <view class="line" />
            <view class="circle" />
          </view>
          <view class="centerText">{{ i18n.invitationCard }}</view>
          <view class="hrLineRight">
            <view class="circle" />
            <view class="line" />
          </view>
        </view>
        <view class="InvitationCards-in-image">
          <image :src="userInfo.pic || 'https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/head04.png'" mode="" />
        </view>
        <view class="userinfo-name">
          <text>{{ userInfo.nickName }}</text>
        </view>
        <view class="InvitationCards-yaoqi">{{ i18n.inviteJoin }}</view>
        <view class="InvitationCards-in-image2">
          <image :src="shareWxCode" />
        </view>
      </view>
    </view>
    <view class="InvitationCards-mian-text">
      <text>{{ i18n.screenshotTips }}</text>
    </view>
  </view>
</template>

<script>
// pages/invitation-cards/invitation-cards.js
var http = require('../../utils/http.js')
var config = require('../../utils/config.js')
var Qr = require('../../utils/wxqrcode')

export default {

  components: {},
  props: {},
  data () {
    return {
      shareWxCode: '',
      userInfo: null
    }
  },

  computed: {
    i18n () {
      return this.$t('index')
    }
  },

  onShow: function () {
    // 头部导航标题
    uni.setNavigationBarTitle({
      title: this.i18n.invitationCard
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.genWeixinCode()
    this.userInfo = uni.getStorageSync('distInfo')
  },
  methods: {
    /**
    * 生成小程序二维码
    */
    genWeixinCode () {
      var cardno = wx.getStorageSync('distCardNo')
      // #ifdef H5 || APP-PLUS
      const code = `${config.domainAddress}/pages/apply-dist-con/apply-dist-con?scene=${cardno}`
      this.shareWxCode = Qr.createQrCodeImg(code, { size: 250 })
      // #endif

      const params = {
        url: '/p/distribution/qrCode/invitation',
        method: 'GET',
        responseType: 'arraybuffer',
        data: {
          page: 'pages/apply-dist-con/apply-dist-con',
          // page: "pages/prod/prod",
          scene: cardno
        },
        callBack: res => {
          // 微信小程序

          this.setData({
            shareWxCode: 'data:image/jpg;base64,' + wx.arrayBufferToBase64(res)
          })
        }
      }

      // #ifdef MP-WEIXIN
      http.request(params)
      // #endif
    }

  }
}
</script>
<style>
@import "./invitation-cards.css";
</style>
